/*
 * =====================================================================================
 *
 *       Filename:  worker_queue.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  05/21/2011 03:18:20 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Ken Chen (Ken), chen_kenz@emc.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#ifndef _WORKER_QUEUE_H_
#define _WORKER_QUEUE_H_

#include <pthread.h>

typedef void (*worker_callback)(void* data);
struct worker_entry;

struct worker_entry_list
{
  struct worker_entry_list* prev;
  struct worker_entry_list* next;
};

struct worker_entry
{
  struct worker_entry_list pending_jobs;
  worker_callback callback;
  void* data;
};

struct worker_queue
{
  pthread_mutex_t worker_lock;
  pthread_cond_t worker_cond;
  struct worker_entry_list pending_jobs;
};

#ifdef __cplusplus
extern "C" {
#endif

void init_worker_queue(struct worker_queue* wq);
void init_job(struct worker_entry* went, 
              worker_callback func, 
              void* data);
int add_job(struct worker_queue* wq, struct worker_entry* went);
int do_jobs(struct worker_queue* wq);

#ifdef __cplusplus
}
#endif

#endif /* _WORKER_QUEUE_H_ */

